package com.ruoyi.business.controller;


import com.ruoyi.business.domain.FileInternetExport;
import com.ruoyi.business.domain.vo.FileInternetExportVo;
import com.ruoyi.business.namage.FileExportManager;
import com.ruoyi.business.service.IFileInternetExportService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 外网导出Controller
 *
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/business/exportNet")
public class FileInternetExportController extends BaseController {
    @Autowired
    private IFileInternetExportService fileInternetExportService;

    @Autowired
    private FileExportManager exportManager;

    /**
     * 查询外网导出列表
     */
    @PreAuthorize("@ss.hasPermi('business:exportNet:list')")
    @GetMapping("/list")
    public TableDataInfo list(FileInternetExportVo fileInternetExportVo, PageQuery pageQuery) {
        return fileInternetExportService.selectPageFileInternetExportList(fileInternetExportVo, pageQuery);
    }

    /**
     * 导出外网导出列表
     */
    @PreAuthorize("@ss.hasPermi('business:exportNet:export')")
    @Log(title = "外网导出", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(FileInternetExport fileInternetExport, HttpServletResponse response) {
        List<FileInternetExport> list = fileInternetExportService.selectFileInternetExportList(fileInternetExport);
        ExcelUtil.exportExcel(list, "外网导出", FileInternetExport.class, response);
    }

    /**
     * 获取外网导出详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:exportNet:query')")
    @GetMapping(value = "/{id}")
    public R<FileInternetExport> getInfo(HttpServletResponse response, @PathVariable("id") Long id) {
        return R.ok(fileInternetExportService.selectFileInternetExportById(id));
    }

    /**
     * 根据附件id返回文件流
     */
    @PreAuthorize("@ss.hasPermi('business:exportNet:query')")
    @GetMapping(value = "getByFileId/{id}")
    public void getByFileId(HttpServletResponse response, @PathVariable("id") Long id) {
        FileInternetExport fileInternetExport = fileInternetExportService.selectFileInternetExportById(id);//获取导出信息
        exportManager.internetExport(response, fileInternetExport);
    }


    /**
     * 新增外网导出
     */
    @PreAuthorize("@ss.hasPermi('business:exportNet:add')")
    @Log(title = "外网导出", businessType = BusinessType.INSERT)
    @PostMapping
    public R<FileInternetExport> add(@RequestBody FileInternetExport fileInternetExport) {
        return R.ok(fileInternetExportService.insertFileInternetExport(fileInternetExport));
    }

    /**
     * 修改外网导出
     */
    @PreAuthorize("@ss.hasPermi('business:exportNet:edit')")
    @Log(title = "外网导出", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<FileInternetExport> edit(@RequestBody FileInternetExport fileInternetExport) {
        return R.ok(fileInternetExportService.updateFileInternetExport(fileInternetExport));
    }

    /**
     * 删除外网导出
     */
    @PreAuthorize("@ss.hasPermi('business:exportNet:remove')")
    @Log(title = "外网导出", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids) {
        return toAjax(fileInternetExportService.deleteFileInternetExportByIds(ids));
    }
}
